package mx.kolobok.noteeditor.ui.keymap.actions;

import mx.kolobok.noteeditor.Note;
import mx.kolobok.noteeditor.ui.Editor;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

/**
 * User:  Nikita Belenkiy
 * Date: 19.05.11
 * Time: 17:22
 */
public class UndoAction extends AbstractAction {

    public UndoAction() {
        super("Undo");
        putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z,
                KeyEvent.CTRL_MASK, true));
    }

    public void actionPerformed(ActionEvent e) {
        Editor source = (Editor) e.getSource();
        Note currentNote = source.getNote();
        if (currentNote != null && currentNote.getUndoManager().canUndo()) {
            currentNote.getUndoManager().undo();
        }
    }
}
